package com.hospital.hms.minio;

import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class MinioDebugExample {
    public static void main(String[] args) {
        try {
            // 创建 MinIO 客户端
            MinioClient minioClient =
                    MinioClient.builder()
                            .endpoint("https://113.45.145.70:9000")
                            .credentials("root", "root1122cheng")
                            .build();

            // 检查存储桶是否存在
            boolean found =
                    minioClient.bucketExists(BucketExistsArgs.builder().bucket("fm-hospital").build());
            if (!found) {
                // 创建存储桶
                minioClient.makeBucket(MakeBucketArgs.builder().bucket("fm-hospital").build());
            } else {
                System.out.println("Bucket 'fm-hospital' already exists.");
            }
        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
            System.out.println("Error occurred: " + e);
        }
    }
}